let n: number
n = 2
console.log(n);
let str: string
str = 'dwa'
console.log(str);
let flag: boolean
flag = false
console.log(flag);
let un: undefined
console.log(un);
let w: null = null
console.log(w);

let s: symbol
s = Symbol('111')
console.log(s);
let d: Date
d = new Date()
console.log(d);

//数组类型
let arr: number[] = [1, 3, 4, 65]
console.log(arr);
let arr1: (number | string)[] = [123, 'afafd', 123]
console.log(arr1);
let arr2: number[] | string[] = [12, 324, 123]
//复杂类型|联合类型
type newparam = number[] | string[]
let arr4: newparam = ['ad', 'v', 'gda']

//自定义对象类型
class Person1 {
  uname: string
  age: number
  constructor(uname: string, age: number) {
    this.uname = uname
    this.age = age
  }
}
let person1: Person = new Person('lisi', 12)
console.log(person1);


//返回值类型为void
function fun1(val1: string): void {
  console.log(val1);

  if (val1 == '666') {
    val1 = '111'
    console.log(val1);

  }
}
fun1('666')

//可选参数
function fun2(num1: number, num2?: number, num3?: number): void {
  console.log(num1, num2, num3);
}
fun2(0, 888, 999)


//函数的返回值和参数的类型
function show(val1: number, val2: number): boolean {
  if (val1 + val2 == 2)
    return true
  return false
}

//函数表达式
const fun = (a: string, b: string): number => {
  let c: string = a + b
  console.log(c);

  if (c.includes('123')) {
    return 2
  }
  return 1
}
let x2 = fun('123', 'abc')
console.log(x2);
//不常用
const add: (num1: number, num2: number) => number = (num1, num2) => {
  return num1 + num2
}